package com.ruoyi.backend.controller;

import com.ruoyi.backend.domain.Task;
import com.ruoyi.backend.service.ITaskService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 任务Controller
 * 
 * @author wjr
 * @date 2025-09-23
 */
@RestController
@RequestMapping("/backend/t_task")
@Api(tags = "任务")
public class TaskController extends BaseController
{
    @Autowired
    private ITaskService taskService;

    /**
     * 查询任务列表
     */
    @PreAuthorize("@ss.hasPermi('backend:t_task:list')")
    @GetMapping("/list")
    @ApiOperation("查询任务列表")
    public TableDataInfo list(Task task)
    {
        startPage();
        List<Task> list = taskService.selectTaskList(task);
        return getDataTable(list);
    }

    /**
     * 获取任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:t_task:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取任务详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(taskService.selectTaskById(id));
    }

    /**
     * 新增任务
     */
    @PreAuthorize("@ss.hasPermi('backend:t_task:add')")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增任务")
    public AjaxResult add(@RequestBody Task task)
    {
        return toAjax(taskService.insertTask(task));
    }

    /**
     * 修改任务
     */
    @PreAuthorize("@ss.hasPermi('backend:t_task:edit')")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改任务")
    public AjaxResult edit(@RequestBody Task task)
    {
        return toAjax(taskService.updateTask(task));
    }

    /**
     * 删除任务
     */
    @PreAuthorize("@ss.hasPermi('backend:t_task:remove')")
    @Log(title = "任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除任务")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(taskService.deleteTaskByIds(ids));
    }

    /**
     * 任务审核
     */
    @PreAuthorize("@ss.hasPermi('backend:t_task:edit')")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping("/auditTask")
    @ApiOperation("任务审核")
    public AjaxResult auditTask(@RequestBody Task task)
    {
        return toAjax(taskService.auditTask(task));
    }

    /**
     * 导出任务列表
     */
    /*@PreAuthorize("@ss.hasPermi('backend:t_task:export')")
    @Log(title = "任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Task task)
    {
        List<Task> list = taskService.selectTaskList(task);
        ExcelUtil<Task> util = new ExcelUtil<Task>(Task.class);
        util.exportExcel(response, list, "任务数据");
    }*/

}
